package com.ruoyi.receipt.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.receipt.domain.TbStatisAnalysis;
import com.ruoyi.receipt.service.ITbStatisAnalysisService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.IdWorker;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 统计分析Controller
 * 
 * @author ruoyi
 * @date 2021-04-06
 */
@RestController
@RequestMapping("/receipt/statisAnalysis")
public class TbStatisAnalysisController extends BaseController
{
    @Autowired
    private ITbStatisAnalysisService tbStatisAnalysisService;

    @Autowired
    private IdWorker idWorker;

    /**
     * 查询统计分析列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TbStatisAnalysis tbStatisAnalysis)
    {
        startPage();
        List<TbStatisAnalysis> list = tbStatisAnalysisService.selectTbStatisAnalysisList(tbStatisAnalysis);
        return getDataTable(list);
    }

    /**
     * 导出统计分析列表
     */
    @Log(title = "导出统计分析", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbStatisAnalysis tbStatisAnalysis)
    {
        List<TbStatisAnalysis> list = tbStatisAnalysisService.selectTbStatisAnalysisList(tbStatisAnalysis);
        ExcelUtil<TbStatisAnalysis> util = new ExcelUtil<TbStatisAnalysis>(TbStatisAnalysis.class);
        return util.exportExcel(list, "analysis");
    }

    /**
     * 获取统计分析详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbStatisAnalysisService.selectTbStatisAnalysisById(id));
    }

    /**
     * 新增统计分析
     */
    @Log(title = "新增统计分析", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbStatisAnalysis tbStatisAnalysis)
    {
        tbStatisAnalysis.setId(idWorker.nextId());
        return toAjax(tbStatisAnalysisService.insertTbStatisAnalysis(tbStatisAnalysis));
    }

    /**
     * 修改统计分析
     */
    @Log(title = "修改统计分析", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbStatisAnalysis tbStatisAnalysis)
    {
        return toAjax(tbStatisAnalysisService.updateTbStatisAnalysis(tbStatisAnalysis));
    }

    /**
     * 删除统计分析
     */
    @Log(title = "删除统计分析", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbStatisAnalysisService.deleteTbStatisAnalysisByIds(ids));
    }
}
